#include<bits/stdc++.h>
using namespace std;
class Trie
{
    public:
    bool isEnd;
    Trie* next[26];
    Trie()
    {
        isEnd=false;
        memset(next,0,sizeof(next));
    }
    void insert(string word)
    {
        Trie *node=this;
        for(char c: word)
        {
            if(node->next[c-'a']==nullptr)
            {
                node->next[c-'a']=new Trie();
            }
            node=node->next[c-'a'];
        }
        node->isEnd=true;
    }
    bool search(string word)
    {
        Trie* node=this;
        for(char c:word)
        {
            if(node->next[c-'a']==nullptr)
            {
                return false;
            }
            node=node->next[c-'a'];
        }
        return node->isEnd;
    }
    bool startWith(string prefix)
    {
        Trie* node=this;
        for(char c:prefix)
        {
            if(node->next[c-'a']==nullptr)
            {
                return false;
            }
            node=node->next[c-'a'];
        }
        return true;

    }
};
int main()
{
Trie *root=new Trie();
root->insert("helloH");
root->insert("word");
cout<<root->search("hel")<<"\n";
cout<<root->startWith("hel")<<"\n";
delete [] root;



}